import { Injectable, Optional } from '@angular/core';
import { UserServiceConfig } from './user';

let nextId = 1;

@Injectable()
export class UserService {
  public id = nextId++;
  private _userName = 'Sherlock Holmes';

  constructor( @Optional() config: UserServiceConfig) {
    if (config) {
      this._userName = config.userName;
    }
  }

  get userName() {
    const suffix = this.id > 1 ? `times ${this.id}` : '';
    return this._userName + suffix;
  }
}
